{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1515"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: sympy in d:\\computer\\anaconda\\lib\\site-packages (1.12)\n",
      "Requirement already satisfied: mpmath>=0.19 in d:\\computer\\anaconda\\lib\\site-packages (from sympy) (1.3.0)\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install sympy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 弧微分 作为曲率的预备知识，先介绍弧微分的概念。 设函数\\(f(x)\\)在区间\\((a,b)\\)内具有连续导数。在曲线\\(y = f(x)\\)上取固定点\\(M_0(x_0,y_0)\\)作为度量弧长的基点（图3 - 27），并规定依\\(x\\)增大的方向作为曲线的正向。对曲线上任一点\\(M(x,y)\\)，规定有向弧段\\(\\overset{\\frown}{M_0M}\\)的值\\(s\\)（简称为弧\\(s\\)）①如下：\\(s\\)的绝对值等于这弧段的长度，当有向弧段\\(\\overset{\\frown}{M_0M}\\)的方向与曲线的正向一致时\\(s>0\\)，相反时\\(s<0\\)。显然，弧\\(s\\)与\\(x\\)存在函数关系：\\(s = s(x)\\)，而且\\(s(x)\\)是\\(x\\)的单调增加函数。下面来求\\(s(x)\\)的导数及微分。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "172  例1计算等边双曲线\\(xy = 1\\)在点\\((1,1)\\)处的曲率。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The curvature at point (1,1) is: 0.707106781186547\n"
     ]
    }
   ],
   "source": [
    "import sympy as sp\n",
    "\n",
    "\n",
    "def curvature(x_val, y_prime_val, y_second_prime_val):\n",
    "    k = abs(y_second_prime_val) / ((1+(y_prime_val)**2)**(3/2))\n",
    "    return k\n",
    "\n",
    "\n",
    "x = sp.Symbol('x')\n",
    "y = 1/x\n",
    "y_prime = sp.diff(y, x)\n",
    "y_second_prime = sp.diff(y_prime, x)\n",
    "\n",
    "x_val = 1\n",
    "y_prime_val = y_prime.subs(x, x_val)\n",
    "y_second_prime_val = y_second_prime.subs(x, x_val)\n",
    "\n",
    "k = curvature(x_val, y_prime_val, y_second_prime_val)\n",
    "print(\"The curvature at point (1,1) is:\", k)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "例2 抛物线\\(y = ax^{2}+bx + c\\)上哪一点处的曲率最大？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The point with maximum curvature is at x = -b/(2*a)\n"
     ]
    }
   ],
   "source": [
    "import sympy as sp\n",
    "\n",
    "\n",
    "def find_max_curvature_point(a, b):\n",
    "    x = sp.Symbol('x')\n",
    "    y_prime = 2 * a * x + b\n",
    "    x_max_curvature = -b / (2 * a)\n",
    "    return x_max_curvature\n",
    "\n",
    "\n",
    "a = sp.Symbol('a')\n",
    "b = sp.Symbol('b')\n",
    "x_max_curvature = find_max_curvature_point(a, b)\n",
    "print(\"The point with maximum curvature is at x =\", x_max_curvature)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "vscode": {
     "languageId": "plaintext"
    }
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
